package com.example.studentmanagement2.service;

import com.example.studentmanagement2.repository.Repository.GradeRepository1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class StatsService {
    @Autowired
    private GradeRepository1 gradeRepository1;

    public Map<String, Double> getClassAverages(String className) {
        List<Object[]> results = gradeRepository1.findAverageScoresByClass(className);
        return results.stream()
                .collect(Collectors.toMap(
                        arr -> (String) arr[0],
                        arr -> (Double) arr[1]
                ));
    }
}